package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.manager.mapper.CategoryBrandMapper;
import com.atguigu.spzx.manager.service.CategoryBrandService;
import com.atguigu.spzx.model.dto.system.CategoryBrandDto;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.entity.product.CateBrand;
import com.atguigu.spzx.model.entity.product.CategoryBrand;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author syh
 * @create 2023-08-22 17:05
 */
@Service
public class CategoryBrandServiceImpl implements CategoryBrandService {
    @Resource
    CategoryBrandMapper categoryBrandMapper;
    @Override
    public PageInfo<CategoryBrand> page(Integer pageNum, Integer pageSize, CategoryBrandDto categoryBrandDto) {
        PageHelper.startPage(pageNum,pageSize,true,true,null);


        return new PageInfo<CategoryBrand>(categoryBrandMapper.selectPage(categoryBrandDto)) ;
    }

    @Override
    public void deleteById(Long id) {
        categoryBrandMapper.deleteById(id);
    }

    @Override
    public void save(CateBrand cateBrand) {
        cateBrand.setCreateTime(new Date());
        cateBrand.setUpdateTime(new Date());
        categoryBrandMapper.save(cateBrand);
    }

    @Override
    public void updateById(CateBrand cateBrand) {
        cateBrand.setUpdateTime(new Date());
        categoryBrandMapper.updateById(cateBrand);
    }

    @Override
    public List<Brand> findBrandByCategoryId(Long categoryId) {
        return categoryBrandMapper.findBrandByCategoryId(categoryId);
    }
}
